package org.example.maven.mapper;

import org.apache.ibatis.annotations.*;
import org.example.maven.pojo.Collection;
import org.example.maven.pojo.Review.ReviewCollectionListTable;
import org.example.maven.pojo.Review.ReviewCollectionSpecie;
import org.example.maven.pojo.list.ListTableCollection;
import org.example.maven.pojo.list.ListTableCollectionAddDetail;
import org.example.maven.pojo.list.ListTableCollectionDetail;
import org.example.maven.pojo.list.ListTableCollectionEditDetail;
import org.example.maven.pojo.utils.SearchCollection;

import java.util.List;

@Mapper
public interface collectionMapper {
    //查询list展示的藏品
    @Select("select collection.id ,internal_id,name,alternate_name,preservation_status,current_location,status,is_deleted,provenance_source.acquisition_date from collection inner join user_review_collection  inner join provenance_source on (collection.id=provenance_source.collection_id and collection.id=user_review_collection.collection_id) where is_add != 0 and is_deleted=0")
    List<ListTableCollection> getAllList();

    //根据藏品编号获取id
    @Select("select id from collection where internal_id=#{internalId}")
    Integer getIdByCollectionInternalId(String internalId);

    //查询藏品数

    Integer getCollectionNumber(SearchCollection searchCollection);

    //查询特点的藏品
    List<ListTableCollection> getSpecificCollection(SearchCollection searchCollection);

    //查询藏品的详情的所有信息
    @Select("select *from collection_details where id=#{id}")
    ListTableCollectionDetail getCollectionDetail(Integer id);

    //根据id获取编辑的藏品信息
    @Select("select collection.id,internal_id,name,alternate_name,classification_subcategory.subcategory_interval as classification_id,era_id,description,preservation_status,weight,current_location,status,img from collection join classification_subcategory on (collection.classification_id=classification_subcategory.id) where collection.id=#{id} and collection.is_deleted=0")
    ListTableCollectionEditDetail getCollectionEditById(Integer id);

    //获取审核藏品的总数
    //@Select("select count(*) from collection inner join user_review_collection on(collection.id=user_review_collection.collection_id) where is_add=0")
    Integer getCollectionReview(ReviewCollectionSpecie reviewCollectionSpecie);

    //获取今日新增的审核藏品数
    @Select("select count(*) from collection inner join user_review_collection on(collection.id=user_review_collection.collection_id) where is_add=0 and  created_at >= CURDATE() AND created_at < CURDATE() + INTERVAL 1 DAY")
    Integer getCollectionReviewDay();

    //获取审核藏品的listTable信息
    @Results({
            @Result(column = "user_name", property = "submitUser")
    })
    @Select("select *from collection_review_user_provenancesource where is_add = 0")
    List<ReviewCollectionListTable> getReviewCollectionListTable();

    //获取特定的审核藏品的信息
    List<ReviewCollectionListTable> getSpecieReviewCollection(ReviewCollectionSpecie reviewCollectionSpecie);

    //进行藏品审核的通过
    void updateCollectionReview(Integer[] id);

    //添加藏品
    void addCollection(ListTableCollectionAddDetail listTableCollectionAddDetail);

    //一次添加多个藏品
    void addCollectionList(@Param("list") List<ListTableCollectionAddDetail> list);

    //添加藏品之后，将待审核藏品添加到待审核表格中
    @Insert("insert into user_review_collection(collection_id,user_id) values (#{collectionId},#{userId})")
    void addReviewCollection(Integer collectionId,Integer userId);

    //添加藏品到待审核表格中
    void addReviewCollectionList(@Param("collectionIds")List<Integer> list,@Param("userId")Integer userId);


}
